{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f610f363",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Author:luoyu\n",
    "# 时间：1014-week07 列表练习 & 初始字典\n",
    "\n",
    "# 目标: \"Don't panic\" ==> \"on tap\"\n",
    "\n",
    "#方法一: 使用list的方法完成\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase) # list() 可以将 str to(转) list\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "# 1.删除后面4个元素 a n i c\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "print(plist)\n",
    "# 2.删除 D ‘\n",
    "plist.remove('D')\n",
    "print(plist)\n",
    "plist.pop(2)\n",
    "print(plist)\n",
    "\n",
    "# 3. 数学案例: 计算 （(a+b)*(c+d)）\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "#  ['o','n','t',''][ a   ,   p        ]\n",
    "print(plist)\n",
    "\n",
    "# 4. 数据插入  实现:'t' 和’‘ 的位置转换\n",
    "#plist.insert(2,plist.pop(3))\n",
    "# print(plist)\n",
    "#plist.pop(2)  #1. 代表删除的内容的值 2.他删除plist的这个值\n",
    "plist.insert(3,plist.pop(2))\n",
    "print(plist)\n",
    "# 5. list to str\n",
    "new_phrase = ''.join(plist)\n",
    "print(plist)\n",
    "print(new_phrase)\n",
    "\n",
    "# plist 改变了原先的状态么? 列表的方法会改变列表本身，如果不想打破或者想保留原先数据的内容，请先使用copy()复制内容\n",
    "\n",
    "# 方法二: 使用切片的方法实现"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
